


function wopen (pic, w, h) {
	window.open(pic, '_blank', 'location=no, menubar=no, resizable=no, scrollbars=yes, status=no, titlebar=no, toolbar=no, width=' +w+ ', height=' +h+ '', '');
}


function href(link) {
	window.open(link, '_parent','','');
}




$(document).ready ( function () {


	$("div.spec-banner").click( function () {
		var li = $(this).find("a.btn").attr("href");
		href(li);
		return false;
		
	
	
	})
	
	$("i.hinter").click ( function () {
		var a = $(this).text();
		$(this).parents("form").find("input[name=q]").attr("value",a);
		//find("input[name=q]").value(a);
		//alert(sa);
	}) 
	
	
	$(".header .col-right a").click ( function () {
		href($(this).attr("href"));
		return false;
	
	})

	

	$("select.counter").change ( function () {
		var l =$(this).children("option:selected").attr("value");
		href(l);
	
	}) 
	

	$('table#tariffstable tr.tc').hover ( function () {
			$(this).css("border","1px solid #ddd");
			
	
	
	},
	function () {
		
				$(this).css("border-color","white");
			
			
		
	
	})
	
	$('table#tariffstable tr').click ( function () {
		var l = $(this).find("a").attr("href");
		href(l);
		return false;
	})

	$("div#pdtog").click ( function () {
		$("div#pricedyn").toggle();
	})
	$("div#pdtog.disabled").click ( function () {
		$("div#pricedyn").hide();
	}) 
	

	
	$("div#pricedyn div").hover ( function () {
		$(this).css("background-color","#CFE9FF");
	},
	function () {
		$(this).css("background-color","#DFF1FF");
	});
	
	$("div#pricedyn div.further").click ( function () {
		$(this).parent().hide();
		$("ul.tabs li").removeClass("active");
		$("ul.tabs li").children("a[href=prices]").parent().addClass("active");
		$("div.tabbed").hide();
		$("div.tabbed.prices").show("fast");
		//href("#prodtabs");
		
	
	
	})
	
	$(".header .order-form input").click( function () {
		//alert("as");
		var portal=$(this).parent().parent("ul").attr("myattr");
		href('/'+portal+'/cart/');
		return false;
	})
	
	$("a#tarifert").click ( function () {
		
		$("ul.tabs li").removeClass("active");
		$("ul.tabs li").children("a[href=tariffs]").parent().addClass("active");
		$("div.tabbed").hide();
		$("div.tabbed.tariffs").show("fast");
		//href("#prodtabs");
		
		return false;
	
	})
	
	$("div#pricedyn div").not(".further").click ( function () {
		$("div#pricedyn").find("input[type=radio]").attr("checked","");
		$(this).find("input[type=radio]").attr("checked","checked");
		$(this).parent().hide();
		
		var p = $(this).attr("attr");
		var t = $(this).attr("attr2");
		//alert(t);
		$("input#prtar").attr("value",t);
		$("div#pdtog var").html(p+" грн");
		
		$("input[type=hidden][name=price]").attr("value",p);
		
	});

	$("ol#product li").hover ( function () {
		$(this).css("border-color","silver");
	
	},
	function () {
		$(this).css("border-color","white");
	});
	
	
	$("ol#product li").click ( function () {
		var l = $(this).find("a.prodtitle").attr("href");
		href(l);
		return false;
	}) 
	

	$("div.filters * ul li").hover ( function () {
		$(this).css("border-color","red");
		$(this).css("text-decoration","line-through");
	},
	function () {
		$(this).css("border-color","#CF7867");
		$(this).css("text-decoration","none");
	});
	
	$("div.filters * ul li").click (function () {
		var l=$(this).children("a").attr("href");
		href(l);
		return false; 
	});
	
	$(".virgin").focusin( function () {
		$(this).removeClass("virgin");
		$(this).html("");
	});

	$("dl#rollover dt").click (function () {
		$(this).siblings("dt").removeClass("active");
		$(this).siblings("dd").hide();
		$(this).addClass("active");
		$(this).next("dd").show();
		return false;
	
	})

	$("a.tarifer").click( function () {
		$("form#carter").exists ( function () {
			var tid=$(this).attr("myattr");
		//alert(tid);
		$("<input type=\"hidden\" value=\""+tid+"\" name=\"tarif\" />").insertAfter("select#price");
		//alert(tid);
		//$("select#price option:selected").val("");
		$("form#carter").submit();
		return false;
		
		});
		
	});

//http://www.queness.com/post/923/create-a-simple-infinite-carousel-with-jquery
//rotation speed and timer
/*
    var speed = 5000;
    var run = setInterval('rotate()', speed);   
     
    //grab the width and calculate left value
    var item_width = $('div.cell').outerWidth(); 
    var left_value = item_width * (-1); 
         
    //move the last item before first item, just in case user click prev button
    $('div.cell:first').before($('div.cell:last'));
     
    //set the default item to the correct position 
    $('div#ts').css({'left' : left_value});
 
    //if user clicked on prev button
    $('td.larr img').click(function() {
 
        //get the right position            
        var left_indent = parseInt($('div#ts').css('left')) + item_width;
 
        //slide the item            
        $('div#ts').animate({'left' : left_indent}, 200, function(){    
 
            //move the last item and put it as first item               
            $('div.cell:first').before($('div.cell:last'));           
 
            //set the default item to correct position
            $('div#ts').css({'left' : left_value});
         
        });
 
        //cancel the link behavior            
        return false;
             
    });
 */
  
    //if user clicked on next button
    $('td.rarr img').click(function() {
         
        //get the right position
        var left_indent = parseInt($('div#ts').css('left')) - item_width;
         
        //slide the item
        $('div#ts').animate({'left' : left_indent}, 200, function () {
             
            //move the first item and put it as last item
            $('div.cell:last').after($('div.cell:first'));                  
             
            //set the default item to correct position
            $('div#ts').css({'left' : left_value});
         
        });
                  
        //cancel the link behavior
		//$(this).animate({'height': '200'},"slow");
        return false;
         
    });        
     
    //if mouse hover, pause the auto rotation, otherwise rotate it
    $('table#scroller').hover(
         
        function() {
            clearInterval(run);
        }, 
        function() {
            run = setInterval('rotate()', speed);   
        }
    ); 
	
	function rotate() {
		$('td.rarr img').click();
	}


// slider ends 

	//alert('123');
	
	$("form#selfer input[type=checkbox]").change( function () {
			
		//var va = $(this).val();
		
		//alert(va);
		$(this).parents("form").submit();
	
	});
	
	
	$("ul.offers li table tr").hover ( function () {
		//alert("12");
		$(this).css("background-color","#E3F2FE");
		},
		function () {
		$(this).css("background-color","white");
	}	
	
	);
	
	$("a.ttog").click ( function () {
		$(this).parents("tr").siblings("tr.togt").toggle();
		return false;
	
	});
	
	$("ul.tabs li a").click ( function () {
		var l = $(this).attr("href");
		$("div.tabbed").hide();
		$("div#"+l+".tabbed").show("fast");
		$(this).parent().siblings().removeClass("active");
		$(this).parent().addClass("active");
		return false;
	});
	
	$("div.gallery dd").click( function () {
		var ni = $(this).children("a").attr("href");
		//ni='/includes/';
		
		$(this).siblings("dt").children("img").attr("src",ni);
		//alert(ni);
		$("div.gallery dd").removeClass("active");
		$(this).addClass("active");
		return false;
	});
	
	
	$("a.r-link").click ( function () {
		$(this).next("input").show();
		$(this).hide();
		return false;
	});
	
	$("hr").each ( function () {
		$(this).after("<hr class=\"s\" />");
	})

	$("img#loader").hide();
	
	//$("p.error").highlightFade({color:'yellow',speed:1300});
	

	
	
	
	$("button").each( function () {
		var tit=$(this).text();
		$(this).parent().append("<a class=\"btn sender\" href=\"#\"><span>"+tit+"</span></a>");
		
		
		$(this).removeAttr("id");
		$(this).hide();
	
	});
	
	$("a.sender").click (function () {
		$(this).parents("form").submit();
		//var ter=$(this).parents("form").attr("action");
		//alert(ter);
		//alert(myf.length);
		return false;
	});
	
	$("img.pie").each ( function () {
		var ps=$(this).attr("src");
		
		
		$(this).after("<div class=\"mypie\" style=\"background-image: url("+ps+")\">&nbsp;</div>");
		
		$(this).hide();
		
	
	})

	

	
	
	
	
	//var fi=$("ol#banners-pager li:first").attr("myattr3");
	
	
	
	
	
	
	
});





