// this switches produt image view in the pop up //

function tglClass(div_id, css_id_add) {
    var target_name = "#" + div_id;
    $(target_name).removeClass();
    $(target_name).addClass(css_id_add);
}
$(document).ready(function () {
    //== apply fancybox to hertz page images ==//
    $(".col1 a").fancybox({
        'titleShow': false
    });
    //== apply fancybox to product image on world phone purchase page======
    $(".phone-option-box a.fancybox, .phonealt-option-box a.fancybox").fancybox({
        'titleShow': false
    });
    $("a.misc").fancybox({
        'titleShow': false
    });
    //================= buy button rollover =====================
    $('.addcart a img').mouseout(function () {
        this.src = '/img/site/order_button_green.gif';
    });
    $('.addcart a img').mouseover(function () {
        this.src = '/img/site/order_button_red.gif';
    });
    //================= english buy button rollover =====================
    $('.addcart a img.english').mouseout(function () {
        this.src = '/img/site/english_order_button_green.gif';
    });
    $('.addcart a img.english').mouseover(function () {
        this.src = '/img/site/english_order_button_red.gif';
    });
    //================= buy button rollover end =====================
    //================= buy button  2rollover =====================
    $('.addcartbig a img').mouseout(function () {
        this.src = '/img/chinaphonebuy/btn01.gif';
    });
    $('.addcartbig a img').mouseover(function () {
        this.src = '/img/chinaphonebuy/btn02.gif';
    });
    //================= buy button 2 rollover end =====================
    //================= buy button  2rollover =====================
    $('#china-rental-button a img').mouseout(function () {
        this.src = '/img/buttons/button_green.gif';
    });
    $('#china-rental-button a img').mouseover(function () {
        this.src = '/img/buttons/button_red.gif';
    });
    //================= buy button 2 rollover end =====================
    //lightbox
    $('.smallimg a').fancybox({
        'titleShow': false
    });
    $('#mainimg a').fancybox({
        'titleShow': false
    });
	
	
	   //================= gallery start =====================
    $('.smallimg img').hover(function () {
        //get image name /path/to/image/{name}-sm{1}.jpg
        var imagePath = $(this).attr('src');
        var matches = imagePath.match(/([a-z0-9]+)-sm(\d)\.jpg/);
        $(this).parent().parent().parent().children('#mainimg').children().children().attr('src', '/img/product-images/' + matches[1] + '-' + matches[2] + '.jpg');
		//console.log($(this).parent().parent().parent().children('#mainimg').children().children());
    });
	
//for when there is more phones than one on page - looks got .mainimg not #mainimg to validate
    $('.smallimg img').hover(function () {
        //get image name /path/to/image/{name}-sm{1}.jpg
        var imagePath = $(this).attr('src');
        var matches = imagePath.match(/([a-z0-9]+)-sm(\d)\.jpg/);
        $(this).parent().parent().parent().children('.mainimg').children().children().attr('src', '/img/product-images/' + matches[1] + '-' + matches[2] + '.jpg');
		//console.log($(this).parent().parent().parent().children('#mainimg').children().children());
    });
	
	
	
		// country drop downs for the alternate world phone page
	$('.english-phone .expand').toggle(function() {
		$(this).attr("style","");
		$(this).addClass('close');
	}, function() {
		$(this).attr("style","");
		$(this).removeClass('close');
	})
	



    //================= gallery end =====================	
    $(".domestic-tabs #tabone").click(function () {
        $(".domestic-tabs #tabone").removeClass("off");
        $(".domestic-tabs #tabone").addClass("active");
        $(".domestic-tabs #tabtwo").addClass("off");
        $(".domestic-sim").hide();
        $(".domestic-phone").show();
    });
    $(".domestic-tabs #tabtwo").click(function () {
        $(".domestic-tabs #tabtwo").removeClass("off");
        $(".domestic-tabs #tabtwo").addClass("active");
        $(".domestic-tabs #tabone").addClass("off");
        $(".domestic-phone").hide();
        $(".domestic-sim").show();
    });
});
